#!/usr/bin/ruby
# ROFLCopter
# Radif Sharafullin 2010
require 'rubygems'
require 'highline/system_extensions'
include HighLine::SystemExtensions

s1= <<EOT;
              LOL:ROFL:ROFL
               ^
        /----------\\
  LOL=====      [ ] \\
          \\          \\
           \\__________ ]
               I    I
          ---------------/
EOT


s2= <<EOT;
    ROFL:ROFL:LOL
               ^
   L    /----------\\
   O======      [ ] \\
   L      \\          \\
           \\__________ ]
               I    I
          ---------------/
EOT

s1_lines=s1.split"\n"
s2_lines=s2.split"\n"
delay =0.1
header="\n"
message="\n\n\n\nControl + X to exit"

say="my roflecopter does"

system "clear"
puts header
puts <<EOT;
    ROFL:ROFL:LOL:ROFL:ROFL
                ^
    L    /----------\\
    O======      [ ] \\
    L      \\          \\
            \\__________ ]
                I    I
           ---------------/
EOT
puts message
system "say \""+say+"\""

drawingThread=Thread.new{

  leftMargin=0;
  loop do
    leftMargin=0 if leftMargin>=55
    leftMargin=leftMargin+1
  system "clear"
  puts header
  
  s1_lines.each do |line|
    margin=" "*leftMargin
    line=margin+line
    puts line
  end
  
  puts message
  sleep delay
  leftMargin=leftMargin+1
  system "clear"
  puts header
  s2_lines.each do |line|
    margin=" "*leftMargin
    line=margin+line
    puts line
  end
  puts message
  sleep delay
end
}

audioThread=Thread.new{
  rofl="rofl " *20
  100000.times do
    system "say \""+rofl+" \""
  end
}
systemThread=Thread.new{
  loop do
    char = get_character
    case char
  	when ?\C-x: print "Exiting...\nLOL\n"; exit;
	  end
    
  end
}
drawingThread.join
audioThread.join
systemThread.join